<template>
  <div class="datalist">
    <el-row class="row" :gutter="4" style="height: 100%">
      <el-col :span="4" class="col" v-if="flowTree">
        <el-tree
          class="tree"
          :data="flowTree"
          :props="{ children: 'sons', label: 'label' }"
          :default-expand-all="true"
          :expand-on-click-node="false"
          @node-click="treeClick"
          highlight-current
        ></el-tree>
      </el-col>
      <el-col :span="20" class="col" style="height: 100%">
        <div class="datalist">
          <div class="header">
            <span style="margin-left: 20px">关键字</span>
            <el-input
              placeholder="请输入关键字"
              v-model="formReq.keyword"
              style="width: 200px; margin-left: 10px"
              clearable
            ></el-input>
            <el-button
              type="primary"
              style="margin-left: 20px"
              size="small"
              @click="
                formReq.pageIndex = 1
                getCaseOtherForms()
              "
            >
              关键字搜索
            </el-button>
          </div>
          <div class="content">
            <div style="flex: auto">
              <el-table
                height="calc(100% - 50px)"
                :data="formRes.Items"
                stripe
                border
                highlight-current-row
              >
                <el-table-column label="流程" width="180px">
                  <template slot-scope="scope">
                    <div style="margin-bottom: 5px">
                      <el-tag type="primary" v-if="scope.row.WFM_Status == 1">
                        {{ scope.row.WFM_StatusDesc }}[{{ scope.row.FRS_Name }}]
                      </el-tag>
                      <el-tag
                        type="success"
                        v-else-if="scope.row.WFM_Status == 2"
                      >
                        {{ scope.row.WFM_StatusDesc }}
                      </el-tag>
                      <el-tag type="danger" v-else>
                        {{ scope.row.WFM_StatusDesc }}
                      </el-tag>
                    </div>
                    <span>{{ scope.row.FLOW_Name }}</span>
                    <!-- <el-link type="primary">状态：{{ scope.row.FRS_Name }}</el-link> -->
                  </template>
                </el-table-column>
                <el-table-column label="发起人及日期" width="140px">
                  <template slot-scope="scope">
                    <div>{{ scope.row.USR_Name }}</div>
                    {{ scope.row.WFM_CreateTime | formatDate }}
                  </template>
                </el-table-column>
                <el-table-column label="表单名" width="300px">
                  <template slot-scope="scope">
                    <span>{{ scope.row.WFM_FormDataName }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="表单信息">
                  <template slot-scope="scope">
                    <div v-if="scope.row.WFM_FormDataCode">
                      搜寻码：{{ scope.row.WFM_FormDataCode }}
                    </div>
                    <div
                      v-for="item in scope.row.FieldValues"
                      :key="item.FFV_ID"
                    >
                      {{ item.FF_DisplayName }}: {{ item.FFV_DisplayValue }}
                    </div>
                  </template>
                </el-table-column>
                <el-table-column fixed="right" label="操作" width="100px">
                  <template slot-scope="scope">
                    <el-button
                      type="text"
                      icon="el-icon-search"
                      @click="toForm(scope.row.COF_FormID)"
                    >
                      查看
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div class="pagination">
              <el-pagination
                layout="total,prev,pager,next,sizes"
                style="float: right"
                background
                :current-page.sync="formReq.pageIndex"
                :total="formRes.Total"
                :page-size="formReq.pageSize"
                :page-sizes="[10, 15, 20]"
                @size-change="
                  (val) => {
                    formReq.pageSize = val
                    getCaseOtherForms()
                  }
                "
                @current-change="getCaseOtherForms()"
              ></el-pagination>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import { getCaseOtherForms, getFlowTrees } from '@/api/core/caseOtherForm'
export default {
  props: ['caseId'],
  data: function () {
    return {
      flowTree: null,
      curFlow: null,
      formReq: {
        caseId: null,
        keyword: '',
        pageIndex: 1,
        pageSize: 10,
      },
      formRes: {
        Items: [],
        Total: 0,
      },
    }
  },
  methods: {
    toForm(formId) {
      this.$router.push({
        name: 'formInfoPage',
        query: { formId },
      })
    },
    treeClick(item) {
      this.curFlow = item.tag
      this.getCaseOtherForms()
    },
    getFlowTrees() {
      getFlowTrees().then(({ data }) => {
        this.flowTree = data
        this.getCaseOtherForms()
      })
    },
    getCaseOtherForms() {
      this.formReq.caseId = this.caseId
      getCaseOtherForms(this.formReq).then(({ data }) => {
        this.formRes = data
      })
    },
  },
  created: function () {
    if (!this.caseId) {
      return
    }
    this.getFlowTrees()
  },
}
</script>
<style>
.el-drawer.rtl {
  overflow: scroll;
}
</style>
<style scoped>
.row {
  height: 100%;
}
.col {
  height: 100%;
}
.col .col_header {
  background: #d9e5fe;
  padding-left: 10px;
  height: 60px;
  display: flex;
  flex-direction: row;
  align-items: center;
}
.col .col_content {
  height: calc(100% - 80px);
  background: white;
  display: flex;
  flex-direction: column;
}
.col .col_content .tree {
  height: 100%;
  width: 100%;
  background: white;
  overflow: auto;
}
</style>
